#!/bin/bash

# docker run --rm --interactive --tty --volume /var/www/docker/app:/app -v ~/.composer:/tmp --user $(id -u):$(id -g) composer install

#more details view
#https://hub.docker.com/_/composer



vendor=vendor

echo -e "\033[32m===================================================================\033[0m"

echo;
echo -e "\033[32m== ★ = ★ = ★ = ★ = ★ = https://hub.docker.com/_/composer = ★ = ★ = ★ = ★ = ★ ==\033[0m"
echo;

echo -e "\033[32m===================================================================\033[0m"
echo;

#like $1=container/Proejct $2=user(default root) #3 composer package name

command="docker run --rm --interactive --tty --volume #Proejct#:/app -v ~/.composer:/tmp #user# composer #param#";
defaultProejct=/var/www/docker/app;

targetProejct=$defaultProejct/$1


if [ ! -d $targetProejct ]; then
  mkdir $targetProejct;
fi;

id="--user $(id -u):$(id -g)";
param=$*;

param=${param/$1/}
if [ -z "$param" ]; then
  param='install';
fi;

#command="a#Proejct#b#user#c#command#d"
command=${command/\#Proejct#/$targetProejct};
command=${command/\#user#/$id};
command=${command/\#param#/$param};
echo $command;
echo;


echo;
echo -e "\033[32mProject path is ===> $targetProejct \033[0m";
echo;


echo;
echo -e "\033[32m===== Composer $param Start  =====\033[0m"
echo;

eval $command
